Skip to content

JsonToRowTest: fix race condition - #36073

Merged
ahmedabu98 merged 6 commits into
apache:masterfrom
derrickaw:fixRaceConditionJsonToRowTest
Sep 15, 2025
Merged

JsonToRowTest: fix race condition#36073
ahmedabu98 merged 6 commits into
apache:masterfrom
derrickaw:fixRaceConditionJsonToRowTest

Conversation

@derrickaw

@derrickaw derrickaw commented Sep 5, 2025

Copy link
Copy Markdown
Collaborator

Fix race condition dealing with global parameter changes.

b/436899963


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses a race condition by avoiding modification of global Jackson parameters. Instead of using overrideDefaultStreamReadConstraints, you've introduced a createJsonFactory method to create configured JsonFactory instances. This is a much safer, thread-safe approach. My review includes one high-severity comment on a bug in the new createJsonFactory method where a parameter is ignored, preventing it from working as described in the Javadoc.

Comment thread sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java Outdated
@derrickaw
derrickaw marked this pull request as ready for review September 5, 2025 21:35
@github-actions

github-actions Bot commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @ahmedabu98 for label java.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

* factory to higher limits. If needed, call this method during pipeline run time, e.g. in
* DoFn.setup. This avoids a data race caused by modifying the global default settings.
*/
public static void increaseDefaultStreamReadConstraints(int newLimit) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. Do we know if users use this method or not?

Any chance we can keep both methods?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed all of the instances inside beam, but for outside that not sure. Just noticed Templates does use it.

Will keep the old method, but take all known users off of it. Sound reasonable? Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure sounds good

@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request effectively addresses a race condition related to global Jackson parameter changes by introducing a JsonFactory with localized stream read constraints. This avoids modifying global state, making the JSON processing more robust and thread-safe. The changes in RowJsonUtils and TableRowJsonCoder are correct and consistent. I have one suggestion to improve the performance and robustness of the newly introduced createJsonFactory method by avoiding repeated reflection.

@derrickaw

Copy link
Copy Markdown
Collaborator Author

Run Java_Amazon-Web-Services2_IO_Direct PreCommit

@derrickaw
derrickaw force-pushed the fixRaceConditionJsonToRowTest branch from 5e18249 to 844dc01 Compare September 10, 2025 19:37
Comment on lines +84 to +92
private static class StreamReadConstraintsHelper {
static void setStreamReadConstraints(JsonFactory jsonFactory, int sizeLimit) {
com.fasterxml.jackson.core.StreamReadConstraints streamReadConstraints =
com.fasterxml.jackson.core.StreamReadConstraints.builder()
.maxStringLength(sizeLimit)
.build();
jsonFactory.setStreamReadConstraints(streamReadConstraints);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why Gemini asked you to put this method in a nested class, but looks good either way.

@derrickaw

Copy link
Copy Markdown
Collaborator Author

Run Java_GCP_IO_Direct PreCommit

@derrickaw

Copy link
Copy Markdown
Collaborator Author

Failure doesn't seem related.

@ahmedabu98
ahmedabu98 merged commit 8a5f57a into apache:master Sep 15, 2025
22 of 24 checks passed
@derrickaw
derrickaw deleted the fixRaceConditionJsonToRowTest branch September 15, 2025 16:08
@derrickaw derrickaw mentioned this pull request Oct 24, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants